
'use strict'

const {deep_copy} = require('./utils')

class Config{
    constructor(config, name){
        Wrapper.check_Model_config_if_ill(config, name)
        this.__config = config
        this.__name = name
        this.__lazy = true
        if('$' === name[0]){
            this.__lazy = false
        }
        if('default' === name){
            this.__lazy = false
        }
    }
    getConfig(extra_config){
        let config = deep_copy(this.__config)
        for(let k in extra_config){
            config[k] = extra_config[k]
        }
        return config
    }
    getName(){
        return this.__name
    }
}

class Wrapper{

    constructor(){

        this.__model_name = ''
        this.__model = null
        this.__lazy = true
        this.__config = {
            'default' : new Config({}, 'default')
        }
    }
    setLazy(lazy){
        this.__lazy = lazy
        return this
    }
    isLazy(){
        return this.__lazy
    }
    setModel(Model, Model_name){
        this.__model = Model
        this.__model_name = Model_name
        return this
    }
    setModelName(Model_name){
        this.__model_name = Model_name
        return this
    }
    getModel(){
        return this.__model
    }
    getModelName(){
        return this.__model_name
    }
    getConfig(config_name, extra_config){
        return this.__config[config_name].getConfig(extra_config)
    }

    config(config, config_name){

        config_name = config_name || 'default'
        Wrapper.check_Model_config_if_ill(config, config_name)
        this.__config[config_name] = new Config(config, config_name)
        return this
    }

    static check_Model_if_ill(Model, Model_name){}
    static check_Model_config_if_ill(config, config_name){}
}

module.exports = Wrapper